﻿import mx.utils.Delegate;

class game.StatusMessagePanel extends arkadium.GUIPanel
{

	private var _smcIcon:MovieClip;
	private var _stxMessage:TextField;
	private var _sbtCancel:Button;
	private var _sbtOkay:Button;
	
	
	
	/**************************************************************************************************\
	getInstance - This function is called to access the sole instance of this class. If the instance 
	doesn't exist, it is created and returned.
	\**************************************************************************************************/
	private static var _pInstance:StatusMessagePanel = null;
	
	public static function getInstance():StatusMessagePanel
	{
		return StatusMessagePanel._pInstance;
	}

	private function StatusMessagePanel()
	{
		// Since this class is a singleton and is linked to a movieclip contained on stage we can set 
		// ourselves to this instance since the constructor is called automatically by flash.
		_pInstance = this;

		super.registerPanel( this, "STATUS_MESSAGE_PANEL" );
		
		_smcIcon.stop();
		setMessage( "" );
		_sbtOkay.onRelease = Delegate.create( this, onOkay );
		_sbtCancel.onRelease = Delegate.create( this, onCancel );
	}
	
	public function onInitialize()
	{
		
	}
	
	
	private function onOkay()
	{
		super.showMe( false );
	}
	
	private function onCancel()
	{
		super.showMe( false );
	}
	
	
	public function onShow( oParams:Object )
	{
		setMessage( oParams.sMessage );
		
		_sbtCancel._visible = true;
		_sbtOkay._visible = false;
		_smcIcon.gotoAndStop( "Load" );
	}
	
	
	public function showLoadingMessage( sMessage:String )
	{
		showMessage( sMessage, "Load" );
	}
	
	public function showSuccessMessage( sMessage:String )
	{
		showMessage( sMessage, "Pass" );
	}
	
	public function showWarningMessage( sMessage:String )
	{
		showMessage( sMessage, "Alert" );
	}
	
	public function showErrorMessage( sMessage:String )
	{
		showMessage( sMessage, "Fail" );
	}
	
	public function hideMessage()
	{
		super.showMe( false );
	}
	
	
	
	private function showMessage( sMessage:String, sIcon:String )
	{
		setMessage( sMessage );
		_smcIcon.gotoAndStop( sIcon );
		super.showMe( true );
	}

	private function setMessage( sMessage:String )
	{
		_stxMessage.text = ( sMessage ) ? sMessage : "?";
	}

	
	/*
	public function setErrorMessage( sMessage:String )
	{
		_sbtCancel._visible = false;
		_sbtOkay._visible = true;
		_smcIcon.gotoAndStop( "Fail" );

		_stxMessage.text = sMessage;
	}
	
	public function setSuccessMessage( sMessage:String )
	{
		_smcLoadingAnim._visible = false;
		_sbtCancel._visible = false;
		_sbtOkay._visible = true;
		_smcIcon.gotoAndStop( "Pass" );

		_stxMessage.text = sMessage;
	}
	*/
	
	
	
	
}